package middlewares

import (
	"github.com/gin-gonic/gin"
	"ucenter/app/service"
)

func AuthLogin(c *gin.Context) {
	token := c.Query("token")
	if token == "" {
		c.JSON(400, &map[string]string{"code": "400", "msg": "token is empty"})
		c.Abort()
		return
	}
	//校验用户token是否合法
	userInfo := service.GetUserService().GetUserInfoByToken(token)
	if userInfo.Id == 0 {
		c.JSON(400, &map[string]string{"code": "400", "msg": "user token not exist!"})
		goto Error
	}
	//用户信息写入context
	c.Set("UID", userInfo.Id)
	return
Error:
	c.Abort()
	return
}

func AuthInternal(c *gin.Context) {

}
